package me.caofeng.controller;

import me.caofeng.annotation.Authentication;
import me.caofeng.enums.ResponseCode;
import me.caofeng.pojo.Response;
import me.caofeng.pojo.SmsCode;
import me.caofeng.pojo.User;
import me.caofeng.service.api.INoticeService;
import me.caofeng.util.CacheUtil;
import me.caofeng.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.print.DocFlavor;
import javax.servlet.http.HttpSession;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.controller
 * @Description:  通知服务
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-06-18 12:56
 * @Version: V1.0
 */
@Controller
@RequestMapping(value = "notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;

    @RequestMapping(value = "code/{phone}",method = RequestMethod.GET)
    @ResponseBody
    public Response getSmsCode(@PathVariable("phone") String phone){
        return noticeService.sendSmsCode(phone);
    }

    @RequestMapping(value = "code",method = RequestMethod.POST)
    @ResponseBody
    public Response<String> verifySmsCode(
            SmsCode smsCode,HttpSession session){
        User user = (User) session.getAttribute(Constant.USER);
        String userId = null == user ? null : user.getUid();
        return noticeService.verifySmsCode(smsCode,userId);
    }
}
